package com.cyurs.netty.nio;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @Author: Cyrus
 * @CreateDate: 2020/11/16
 */
public class ChannelDemo1 {
    public static void main(String[] args) throws Exception {
        String str = "hello World";
        FileOutputStream fileOutputStream = new FileOutputStream("E:\\a.txt");
        FileChannel channel = fileOutputStream.getChannel();
        ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
        byteBuffer.put(str.getBytes());
        byteBuffer.flip();
        channel.write(byteBuffer);
        fileOutputStream.close();

    }
}
